﻿<Window
	xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
	xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
	x:Class="Microsoft.Research.ScientificWorkflow.SecurityControls.PermissionSettingsCtrl"
	x:Name="permissionSettingsWindow" Title="Permission Settings" Width="400" Height="424"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
    mc:Ignorable="d" AllowsTransparency="True" WindowStyle="None" ResizeMode="NoResize" Background="{x:Null}">

    <Window.Resources>
        <DataTemplate x:Key="lstboxTemplate">
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="21.5"/>
                    <ColumnDefinition Width="*" MinWidth="26.098"/>
                </Grid.ColumnDefinitions>
                <Image Grid.ColumnSpan="1" Width="16" HorizontalAlignment="Center" Source="{Binding Path=Principal.ImagePath}" VerticalAlignment="Center" Height="16" />
                <TextBlock Grid.Column="1" Margin="1,0,0,0" Text="{Binding Path=DisplayName}" AutomationProperties.AutomationId="{Binding Path=Name}"/>
            </Grid>
        </DataTemplate>
        <Style x:Key="PopupCloseButton" BasedOn="{x:Null}" TargetType="{x:Type Button}">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type Button}">
                        <Grid>
                            <Rectangle Fill="#FFCCCCCC" Stroke="{x:Null}" RadiusX="4.5" RadiusY="4.5" x:Name="rectangle"/>
                            <Rectangle Fill="#FF4F4F4F" Stroke="{x:Null}" RadiusX="0" RadiusY="0" Margin="8,3.5,7,3.5" RenderTransformOrigin="0.5,0.5">
                                <Rectangle.RenderTransform>
                                    <TransformGroup>
                                        <ScaleTransform ScaleX="1" ScaleY="1"/>
                                        <SkewTransform AngleX="0" AngleY="0"/>
                                        <RotateTransform Angle="-34.039"/>
                                        <TranslateTransform X="0" Y="0"/>
                                    </TransformGroup>
                                </Rectangle.RenderTransform>
                            </Rectangle>
                            <Rectangle Fill="#FF4F4F4F" Stroke="{x:Null}" RadiusX="0" RadiusY="0" RenderTransformOrigin="0.5,0.5" Margin="8,3.5,7,3.5">
                                <Rectangle.RenderTransform>
                                    <TransformGroup>
                                        <ScaleTransform ScaleX="-1" ScaleY="1"/>
                                        <SkewTransform AngleX="0" AngleY="0"/>
                                        <RotateTransform Angle="34.039"/>
                                        <TranslateTransform X="0" Y="0"/>
                                    </TransformGroup>
                                </Rectangle.RenderTransform>
                            </Rectangle>
                        </Grid>
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsFocused" Value="True"/>
                            <Trigger Property="IsDefaulted" Value="True"/>
                            <Trigger Property="IsMouseOver" Value="True">
                                <Setter Property="Fill" TargetName="rectangle" Value="#FFADADAD"/>
                            </Trigger>
                            <Trigger Property="IsPressed" Value="True"/>
                            <Trigger Property="IsEnabled" Value="False"/>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    </Window.Resources>

    <Grid x:Name="LayoutRoot">
        <Border BorderBrush="#FFBDBDBD" BorderThickness="1,1,2,2" CornerRadius="4,4,4,4">
            <Border.Background>
                <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                    <GradientStop Color="#FFF7F7F7" Offset="0"/>
                    <GradientStop Color="#FFF1F1F1" Offset="1"/>
                </LinearGradientBrush>
            </Border.Background>
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="28"/>
                    <RowDefinition Height="*"/>
                    <RowDefinition Height="38"/>
                </Grid.RowDefinitions>
                <!--Window title border-->
                <Border MouseLeftButtonDown="OnHeaderMouseDown" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Width="Auto" Grid.Row="0" CornerRadius="4,4,0,0">
                    <Border.Background>
                        <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                            <GradientStop Color="#FFF7F7F7" Offset="0"/>
                            <GradientStop Color="#FFE9E9E9" Offset="1"/>
                        </LinearGradientBrush>
                    </Border.Background>
                    <Grid>
                        <TextBlock HorizontalAlignment="Left" Margin="5,0,0,0" VerticalAlignment="Center" FontSize="14" Foreground="#FF5F5F5F" Text="Permission Settings" TextWrapping="Wrap"/>
                        <Button HorizontalAlignment="Right" Click="OnCancelClick" Margin="0,5.5,5,5.5" Style="{DynamicResource PopupCloseButton}" Width="17" Content="Button"/>
                    </Grid>
                </Border>

                <!--Main content area-->
                <Border Grid.Row="1" Background="#FFFFFFFF">
                    <StackPanel Margin="15,10,10,10">
                        <!--Users / Groups-->
                        <StackPanel>
                            <TextBlock Text="Users / Groups" TextWrapping="Wrap" FontWeight="Normal" Margin="0,0,0,2"/>
                            <ListBox Name="lstBxSecurityPrincipals" ItemsSource="{Binding Path=SecurityPrincipals}" ItemTemplate="{StaticResource lstboxTemplate}"
                                     IsSynchronizedWithCurrentItem="True" MinHeight="90" Height="90" BorderBrush="#FFCACACA"/>
                            <StackPanel Orientation="Horizontal" HorizontalAlignment="Right" Margin="0,5,0,0">
                                <Button Width="60" Click="OnAddUserClick" Content="Add" Name="btnAddUsrGrp"/>
                                <Button Width="60" Click="OnRemoveUserClick" Content="Remove" Name="btnRemoveUsrGrp" Margin="5,0,0,0"/>
                            </StackPanel>
                        </StackPanel>

                        <!--Permissions-->
                        <ListView Name="lstVwPermissions" 
                                  DataContext="{Binding ElementName=lstBxSecurityPrincipals, Path=SelectedItem}" ItemsSource="{Binding Path=AvailablePermissions}"
                                  IsEnabled="{Binding Path=NotOwnerOrAdmin}"
                                  SelectionMode="Single" IsSynchronizedWithCurrentItem="True" Height="120" MinHeight="120" Margin="0,10,0,0">
                            <ListView.View>
                                <GridView>
                                    <GridViewColumn Header="Permission" DisplayMemberBinding="{Binding Path=DisplayName}" Width="200"/>
                                    <GridViewColumn Header="Allow" Width="70">
                                        <GridViewColumn.CellTemplate>
                                            <DataTemplate>
                                                <Grid>
                                                    <CheckBox Margin="20,5,0,0" HorizontalAlignment="Left" VerticalAlignment="Top" AutomationProperties.AutomationId="{Binding Path=AllowPrivilege}" IsChecked="{Binding Path=AllowPrivilege.ProcessedPrivilege, Mode=TwoWay}"/>
                                                </Grid>
                                            </DataTemplate>
                                        </GridViewColumn.CellTemplate>
                                    </GridViewColumn>
                                    <GridViewColumn Header="Deny" Width="70">
                                        <GridViewColumn.CellTemplate>
                                            <DataTemplate>
                                                <Grid>
                                                    <CheckBox Margin="20,5,0,0" HorizontalAlignment="Left" VerticalAlignment="Top" AutomationProperties.AutomationId="{Binding Path=DenyPrivilege}"  IsChecked="{Binding Path=DenyPrivilege.ProcessedPrivilege, Mode=TwoWay}"/>
                                                </Grid>
                                            </DataTemplate>
                                        </GridViewColumn.CellTemplate>
                                    </GridViewColumn>
                                </GridView>
                            </ListView.View>
                        </ListView>

                        <!--Versioning checkbox-->
                        <CheckBox Content="Inherit permissions when new versions are created" Margin="0,10,0,0" IsChecked="True" IsEnabled="False"/>

                        <DockPanel LastChildFill="False" Margin="0,10,0,0">
                            <DockPanel DockPanel.Dock="Left" Margin="0,3,0,0" HorizontalAlignment="Left" VerticalAlignment="Top" Name="errorWfName" Visibility="Visible">
                                <Grid DockPanel.Dock="Left" Margin="2,0" Width="12" Height="12">
                                    <Ellipse Fill="#FFC42A2A" Stroke="{x:Null}"/>
                                    <Path Fill="#FFFFFFFF" Stretch="Fill" Stroke="{x:Null}" StrokeThickness="2" Margin="4.94,2.235,4.644,5.12" Data="M11.701627,8.0009042 L12.372672,15.173164 14.011686,15.241177 14.56827,7.8270056 z"/>
                                    <Path Fill="#FFFFFFFF" Stretch="Fill" Stroke="{x:Null}" StrokeThickness="2" Margin="5.121,0,4.779,1.746" VerticalAlignment="Bottom" Height="2.1" Data="M11.395564,17.238573 L14.853121,17.333691 14.771832,21.163108 11.102494,20.999791 z"/>
                                </Grid>
                            </DockPanel>
                            
                            <!--Info text-->
                            <TextBlock Margin="3,0,0,0" Text="Owners and Administrators will have all permissions for the workflow." TextWrapping="Wrap" DockPanel.Dock="Left"/>
                        </DockPanel>
                    </StackPanel>
                </Border>

                <!--Ok and Cancel buttons-->
                <Button HorizontalAlignment="Right" Width="70" IsCancel="True" Click="OnCancelClick" Content="Cancel" Margin="0,0,10,0" VerticalAlignment="Center" Grid.Row="2" Name="btnCancel"/>
                <Button HorizontalAlignment="Right" Width="70" IsEnabled="True" Click="OnOkClick" Content="OK" Margin="0,0,85,0" VerticalAlignment="Center" Grid.Row="2" d:LayoutOverrides="Height" Name="btnOk"/>
            </Grid>
        </Border>
    </Grid>
</Window>